package com.atguigu.mvc.controller;/*
@author joker
@create 2022-05-02 13:08
SpringMVCdemo01
*/

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

@Controller
public class ParamController {
    /*测试servlet自带的获取请求参数*/
    @RequestMapping("/testServletAPI")
    public String testServletAPI(HttpServletRequest request){
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println("username="+username);
        System.out.println("password="+password);
        return "success";
    }

    /*测试springmvc的获取参数*/
    @RequestMapping("/testParam")
    public String testParameters(@RequestParam("user_name") String username,
                                  String password,
                                  String[] hobby)
    {
        //多请求参数中出现多个同名的请求参数,可以在控制器方法的形参位置设置字符串类型 或 字符串数组 来接收此参数
        //若使用字符串类型的形参,最终结果为请求参数的每一个值之间使用 , 进行拼接

        System.out.println("username="+username);
        System.out.println("password="+password);
        System.out.println("hobby="+ Arrays.toString(hobby));
        return "success";
    }
}
